package com.gpnu.crm.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gpnu.crm.domain.Customer;
import com.gpnu.crm.domain.CustomerTransfer;
import com.gpnu.crm.mapper.CustomerMapper;
import com.gpnu.crm.mapper.CustomerTransferMapper;
import com.gpnu.crm.query.QueryObject;
import com.gpnu.crm.service.ICustomerTransferService;
import com.gpnu.crm.util.UserContext;

@Service
public class CustomerTransferServiceImpl implements ICustomerTransferService{
	@Autowired 
	private CustomerTransferMapper customerTransferMapper;
	@Autowired
	private CustomerMapper customerMapper;
	
	public void save(CustomerTransfer entity) {
		// 修改
/*		customerMapper.updateCustomerInfo(
				transfer.getCustomer().getId(), 
				transfer.getNewSeller().getId(), 
				null);
		
		//填入录入时间
		transfer.setOperateTime(new Date());
		transferMapper.insert(transfer);*/
		
	    entity.setOperateTime(new Date());
	    //entity.setOperator(UserContext.getCurrentUser());
	    this.customerTransferMapper.insert(entity);	    
	    this.customerMapper.updateCustomerInfo(entity.getCustomer().getId(), entity
	        .getNewSeller().getId(), Customer.STATUS_NORMAL);
	}

	public PageInfo<CustomerTransfer> list(QueryObject qo) {
		PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
		List<CustomerTransfer> list = customerTransferMapper.selectAll(qo);
		return new PageInfo<>(list);
	}
}
